package cn.edu;

import cn.edu.model.Book;
import cn.edu.model.Library;
import cn.edu.model.Periodical;
import cn.edu.model.Publication;

import java.util.Scanner;

/**
 * @author 文欣雨
 * @version V1.0
 * @Package cn.edu
 * @date 2023/2/6 19:12
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Library library = null;
        a:
        while (true) {
            System.out.println("请选择功能: ");
            System.out.println("1: 创建图书馆;");
            System.out.println("2: 添加出版物;");
            System.out.println("3: 查询出版物;");
            System.out.println("4: 删除出版物;");
            System.out.println("5: 显示所有出版物;");
            System.out.println("6: 退出系统;");
            int i = scan.nextInt();
            switch (i) {
                case 1: {
                    System.out.println("请输入图书馆的容量");
                    int n = scan.nextInt();
                    library = new Library(n);
                    break;
                }
                case 2: {
                    if (library == null) {
                        System.out.println("请初始化图书馆");
                        break;
                    }
                    System.out.println("请选择出版物的类型: \n" +
                            "1: 图书;\n" +
                            "2: 期刊;");
                    int n = scan.nextInt();
                    Publication publication = null;
                    System.out.println("请输入出版物名称: ");
                    String name = scan.next();
                    System.out.println("请输入出版物作者名: ");
                    String action = scan.next();
                    System.out.println("请输入出版物价格: ");
                    double price = scan.nextDouble();
                    if (n == 1) {
                        System.out.println("请输入图书页数: ");
                        int number = scan.nextInt();
                        publication = new Book(name, action, price, number);
                    } else if (n == 2) {
                        System.out.println("请输入期数: ");
                        int number = scan.nextInt();
                        publication = new Periodical(name, action, price, number);
                    } else {
                        System.out.println("请输入正确的选项");
                        break;
                    }
                    library.addPublication(publication);
                    break;
                }
                case 3: {
                    if (library == null) {
                        System.out.println("请初始化图书馆");
                        break;
                    }
                    System.out.println("请输入要查询的出版物名称: ");
                    String name = scan.next();
                    Publication publication = library.selectPublication(name);
                    System.out.print("查询到的出版物为: ");
                    publication.show();
                    break;
                }
                case 4: {
                    if (library == null) {
                        System.out.println("请初始化图书馆");
                        break;
                    }
                    System.out.println("请输入要删除的出版物名称: ");
                    String name = scan.next();
                    library.deletePublication(name);
                    break;
                }
                case 5: {
                    if (library == null) {
                        System.out.println("请初始化图书馆");
                        break;
                    }
                    library.show();
                    break;
                }
                case 6: {
                    break a;
                }
                default: {
                    System.out.println("请输入正确的选项");
                    break;
                }
            }
        }
        scan.close();
    }
}
